// 完整引入
// import 'core-js'
// 按需加载
// import 'core-js'
// import 'core-js/actual/promise/index.js'
import count from "./js/count.js";
import sum from "./js/sum.js"


import "./css/index.css"
import "./css/iconfont.css"
import "./less/index.less"
import "./sass/index.sass"
import "./sass/index.scss"
import "./stylus/index.styl"

console.log(count(1, 2));
console.log(sum(1, 2, 3, 4))

document.querySelector("#btn").addEventListener("click", function () {
    // "math"将来就会作为[name]的值显示。
    import(/* webpackChunkName: "math" */ "./js/math.js").then(({mul}) => {
        alert(mul(2, 1));
    });
})
// 判断是否支持HMR功能，手动添加每个js文件
// 实际项目开发中直接vue或者react提供的loader就可以了，不用手动添加
// if (module.hot) {
//     module.hot.accept("./js/count.js", function (count) { // 第二个是回调函数，不写也可以
//         const result1 = count(2, 1);
//         console.log(result1);
//     });
//
//     module.hot.accept("./js/sum.js", function (sum) {
//         const result2 = sum(1, 2, 3, 4);
//         console.log(result2);
//     });
// }


// 添加promise代码
const promise = Promise.resolve();
promise.then(() => {
    console.log("hello promise");
});

const arr = [1, 2, 3, 4]
console.log(arr.includes(1))


if ("serviceWorker" in navigator) {
    window.addEventListener("load", () => {
        navigator.serviceWorker
            .register("/service-worker.js")
            .then((registration) => {
                console.log("SW registered: ", registration);
            })
            .catch((registrationError) => {
                console.log("SW registration failed: ", registrationError);
            });
    });
}